<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;
use Tools\Category;
//角色组控制器
class AuthgroupController extends CommonController{
	//列表
	public function index(){
		$pageNum=I('pageNum',1,intval);//第几页
		$numPerPage=I('numPerPage',10,intval);//每页显示条数

		//获取排序的字段及排序方式
		$orderField=$_POST['_order']?$_POST['_order']:'id';
		$orderDirection=$_POST['_sort']?$_POST['_sort']:'asc';

		//组合排序字符串
		$orders=($orderField.' '.$orderDirection);


		$db=M('authgroup');
		//获取总数据条数
		$count=$db->count();
		$this->assign('totalCount',$count);//数据的总条数
		$this->assign('numPerPage',$numPerPage);//每页显示多少条
		$this->assign('pageNumShown',6);//页标数字多少个
		$this->assign('currentPage',$pageNum);//当前是第几页
		$page= new \Think\Page($count,$numPerPage);
		$this->group=$db->limit($numPerPage)->Page($pageNum)->order($orders)->select();
		//权限菜单的显示与隐藏	
		$this->assign('authGroup_addId',43);//添加
		$this->assign('authGroup_delId',50);//删除
		$this->assign('authGroup_rulesId',47);//权限配置
		$this->assign('authGroup_editId',45);//编辑
		$this->assign('authGroup_statusId',117);//状态变更
		$this->display();
	}
	//添加角色权限
	public function rules(){
		if(!empty($_POST)){
			$id=$_POST['id'];
			$rules=$_POST['rule_id'];
			$rules=implode(',',$rules);
			$db=M('authgroup');
			$result=$db->where(array('id'=>$id))->setField('rules',$rules);
			if($result){
				$this->success('配置成功');
			}else{
				$this->error('配置失败');
			}

		}else{
			$id = $_GET['id'];
			$db=M('authgroup');
			$rules=$db->where(array('id'=>$id))->getField('rules');
			$this->assign('rules',$rules);
			//$this->rules=explode(',',$rules);
			$authrule=M('authrule');
			$field=array('id','title','pid');
			$note=$authrule->field($field)->order('sort')->select();
			$note=Category::unlimitedForLayer($note);
			// p($note);
			$this->assign('note',$note);
			$this->display();
		}
	}

}